#ifndef BLUETOOTH_CONTEXT
#define BLUETOOTH_CONTEXT
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
//蓝牙键鼠主服务
#define SERVICE_UUID           "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // 服务UUID
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E" // 接收特征码
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E" // 发送特征码
#define CHARACTERISTIC_UUID_CX "6E400004-B5A3-F393-E0A9-E50E24DCCA9E" // 发送特征码

//DEMO服务
#define DEMO_SERVICE_UUID           "4F7A1C3A-9E5B-4D2F-8A73-BC1E6F2D9A04" // 服务UUID
#define DEMO_CHARACTERISTIC_UUID_RX "4F7A1C3B-9E5B-4D2F-8A73-BC1E6F2D9A04" // 接收特征码
#define DEMO_CHARACTERISTIC_UUID_TX "4F7A1C3C-9E5B-4D2F-8A73-BC1E6F2D9A04" // 发送特征码
#define DEMO_CHARACTERISTIC_UUID_CX "4F7A1C3D-9E5B-4D2F-8A73-BC1E6F2D9A04" // 发送特征码

struct UUIDS {
  String serviceUUID;
  String txCharacteristicUUID;
  String rxCharacteristicUUID;
  String cxCharacteristicUUID;
};

class BluetoothContext{
private:
  BLEServer *pServer = nullptr;
  BLECharacteristic * pTxCharacteristic = nullptr;
  BLECharacteristic * pRxCharacteristic = nullptr;
  BLECharacteristic * pCxCharacteristic = nullptr;
  bool deviceConnected = false;
  bool oldDeviceConnected = false;
  uint8_t txValue = 0;
  unsigned long interval = 2000; // 默认为 2 秒慢闪
  unsigned long lastMillis = 0;  // 用于记录时间
public:
  void init(const String& deviceName);
  void setDeviceConnected(bool connected) { 
    deviceConnected = connected;
  }
  bool isDeviceConnected() const { 
    bool connected;
    connected = deviceConnected;
    return connected;
  }
  void setInterval(unsigned long ms) { interval = ms; }
  unsigned long getInterval() const { return interval; }
  BLECharacteristic* getTxCharacteristic() const { return pTxCharacteristic; }
};
#endif // BLUETOOTH_CONTEXT